ngx.shared.shared_data={}

local concat = table.concat
local upstream = require "ngx.upstream"
local get_servers = upstream.get_servers
local get_upstreams = upstream.get_upstreams

local us = get_upstreams()

local index = 1

for _, u in ipairs(us) do
    local srvs, err = get_servers(u)
	for _, srv in ipairs(srvs) do
	    local first = true
	    for k, v in pairs(srv) do
		if k == "addr" then
		    tmpData={}
		    tmpData["weight"]=index
		    tmpData["server"]=v
		    ngx.shared.shared_data[index]=tmpData
		    index = index + 1
		end
	    end
	end
end

ngx.shared.index = index